/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package testserver;

import com.felisberto.serialfwder.gui.PortChooser;
import com.felisberto.serialfwder.serial.SerialDataListener;
import com.felisberto.serialfwder.serial.SerialPortReceiver;
import com.felisberto.serialfwder.socket.server.NettyServer;
import gnu.io.CommPortIdentifier;

/**
 *
 * @author Filipe
 */
public class Server implements SerialDataListener {

    NettyServer socket_server;
    SerialPortReceiver serial_port;

    public void startSerialListening() {
        if (serial_port == null) {
            serial_port = PortChooser.createReceiver();
        }
        if (socket_server != null) {
            serial_port.addListener(this);
        }
    }

    public void startSocketServer(int port) {
        if (socket_server == null) {
            socket_server = new NettyServer(port);

            socket_server.startServer();

            if (serial_port != null) {
                serial_port.addListener(this);
            }
        }
    }

    public void receive(String data) {

        socket_server.sendData(data);
    }
}
